package action.ManagerAction;

import com.alibaba.fastjson.JSON;
import com.opensymphony.xwork2.ActionSupport;
import common.Pagination;
import entity.CroChangegoods;
import entity.CroReturngoods;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import service.CroChangegoodService;
import vo.CroChangegoodsVo;

import java.util.List;

/**
 * Created by wsx on 2017/5/13.
 */
public class CroChangegoodsAction extends ActionSupport{
    @Autowired
    private CroChangegoodService croChangegoodService;

    private List<CroChangegoods> croChangegoodsList;
    private CroChangegoods croChangegoods;
    private CroChangegoodsVo croChangegoodsVo;
    private CroChangegoodsVo recorCroChangegoodsvo;
    private int pageIndex;
    private int pageCount;
    private int pageSize = 10;
    private String jsonObject;
    private String id;
    private String successResult;
    private Double totalprice;
    private String yesorno;
    /*
   * 所有换货
   * */
    @RequiresPermissions("user:select")
    public String changeGoods(){
        Pagination<CroChangegoods> page;
        if(pageIndex==0){
            page=croChangegoodService.findAllChangegoods(1,pageSize);
        }else{
            page=croChangegoodService.findAllChangegoods(pageIndex,pageSize);
        }
        setPageCount((int) page.getPagesCount());
        setPageIndex((int) page.getCurIndex());
        setCroChangegoodsList(page.getItems());
        return "success";
    }

    /*
    * 按条件找出换货
    * */
    @RequiresPermissions("user:select")
    public String findChangeGoodsByCondiction(){
        System.out.println("findReturnGoodsAction "+"username:"+croChangegoodsVo.getUsername()+
                "status:"+croChangegoodsVo.getChangeStatus()+"id:"+id);
        Pagination<CroChangegoods> page;
        if(pageIndex==0){
           page=croChangegoodService.findChangegoodsByConditction(1,pageSize,croChangegoodsVo);
        }else{
            page=croChangegoodService.findChangegoodsByConditction(pageIndex,pageSize,croChangegoodsVo);
        }
        setPageCount((int) page.getPagesCount());
        setPageIndex((int) page.getCurIndex());
//        setCroReturngoodsList(page.getItems());
//        setRecorCroReturngoodsVo(croReturngoodsVo);
//        setJsonObject(JSON.toJSONString(croReturngoodsVo));
        setCroChangegoodsList(page.getItems());
        setRecorCroChangegoodsvo(croChangegoodsVo);
        setJsonObject(JSON.toJSONString(croChangegoodsVo));
        return SUCCESS;
    }
      /*
        * 根据id删除换货申请
        * */
      @RequiresPermissions("user:delete")
      public String deleteChangegoods(){
        System.out.println("id："+id);
        if(croChangegoodService.deleteChangegoods(id)){
            successResult = "删除成功！";
        }else{
            successResult = "删除失败！";
        }
        return SUCCESS;
    }
        /*
        * 获取换货信息详情
        * */
        @RequiresPermissions("user:select")
    public String getChangegoodsDetail(){
        System.out.println("getChangegoodsDetailAction;id:"+id);
        croChangegoods=croChangegoodService.getChangegoodsDetail(id);
        return SUCCESS;
    }

    /*
* 改变换货状态
* */
    @RequiresPermissions("user:update")
    public String changegoodsStatus(){
        System.out.println(" changegoodsaction,id:"+id+" yesorno"+yesorno);
        String status=null;
        if(!yesorno.equals("-1")) {
            if (yesorno.equals("0")) {
                System.out.println("---------");
                status = "2";
            } else {
                status = "1";
            }
        }
        if(croChangegoodService.changeGoodsStatus(id,status)) {
            return SUCCESS;
        }else{
            return null;
        }
    }

    public CroChangegoods getCroChangegoods() {
        return croChangegoods;
    }

    public void setCroChangegoods(CroChangegoods croChangegoods) {
        this.croChangegoods = croChangegoods;
    }

    public CroChangegoodsVo getCroChangegoodsVo() {
        return croChangegoodsVo;
    }

    public void setCroChangegoodsVo(CroChangegoodsVo croChangegoodsVo) {
        this.croChangegoodsVo = croChangegoodsVo;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public int getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public int getPageCount() {
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public String getJsonObject() {
        return jsonObject;
    }

    public void setJsonObject(String jsonObject) {
        this.jsonObject = jsonObject;
    }

    public String getSuccessResult() {
        return successResult;
    }

    public void setSuccessResult(String successResult) {
        this.successResult = successResult;
    }

    public Double getTotalprice() {
        return totalprice;
    }

    public void setTotalprice(Double totalprice) {
        this.totalprice = totalprice;
    }

    public String getYesorno() {
        return yesorno;
    }

    public void setYesorno(String yesorno) {
        this.yesorno = yesorno;
    }

    public CroChangegoodService getCroChangegoodService() {
        return croChangegoodService;
    }

    public void setCroChangegoodService(CroChangegoodService croChangegoodService) {
        this.croChangegoodService = croChangegoodService;
    }

    public CroChangegoodsVo getRecorCroChangegoodsvo() {
        return recorCroChangegoodsvo;
    }

    public void setRecorCroChangegoodsvo(CroChangegoodsVo recorCroChangegoodsvo) {
        this.recorCroChangegoodsvo = recorCroChangegoodsvo;
    }
    public List<CroChangegoods> getCroChangegoodsList() {
        return croChangegoodsList;
    }
    public void setCroChangegoodsList(List<CroChangegoods> croChangegoodsList) {
        this.croChangegoodsList = croChangegoodsList;
    }

}
